﻿// -----------------------------------------------------------------------
// <copyright file="Accesibility.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Metal.Controller
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// Provide access to player forms.
    /// </summary>
    public static class Accesibility
    {
        /// <summary>
        /// Gets a form instance
        /// </summary>
        /// <param name="formName">The form to return</param>
        /// <returns>Returns desired form</returns>
        public static Form GetFormInstance(string formName)
        {
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            foreach (Form form in Application.OpenForms)
            {
                if (form.Name == formName)
                {
                    return form;
                }
            }

            return null;
        }

        /// <summary>
        /// Instantiate a form via reflection
        /// </summary>
        /// <param name="strNamespace">The namespace of the form</param>
        /// <param name="className">The name of the form</param>
        /// <returns>Returns desired form</returns>
        public static Form CreateFormInstance(string strNamespace, string className)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(strNamespace);
            Type t = assembly.GetType(className);
            Form customForm = (Form)Activator.CreateInstance(t);

            return customForm;
        }

        public static void RestartApplication()
        {
            Application.Restart();
        }

        public static void CloseApplication()
        {
            if (Core.Player.Status.PlaybackStatus == Core.Player.Status.StatusEnum.Playing)
            {
                Core.Player.Playback.Instance.Stop();
            }

            Application.Exit();
        }
    }
}
